import React from "react";
import "./App.css";
import { BrowserRouter, Switch, Route, Redirect } from "react-router-dom";
import AddressList from "./pages/address/list";
import AddressAdd from "./pages/address/add";
import Login from "./pages/login/index.jsx";

function App() {
    return (
        <div className="App">
            <BrowserRouter>
                <Switch>
                    <Redirect exact from="/" to="/address/list" />
                    <Route
                        path="/address/list"
                        render={(props) => {
                            if (window.sessionStorage.getItem("user")) {
                                return <AddressList {...props} />;
                            } else {
                                return <Redirect to="/login" />;
                            }
                        }}
                    />
                    <Route path="/address/add" component={AddressAdd} />
                    <Route path="/login" component={Login} />
                </Switch>
            </BrowserRouter>
        </div>
    );
}

export default App;
